home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000058_icon-group-sender_Mon Mar 12 12:43:04 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f2CJgiY18384
for icon-group-addresses; Mon, 12 Mar 2001 12:42:44 -0700 (MST)
Message-Id: <200103121942.f2CJgiY18384@baskerville.CS.Arizona.EDU>
Date: Mon, 12 Mar 2001 10:35:58 -0600
From: gep2@terabites.com
Subject: Re: New Scientist Puzzle
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2911
Several things I don't understand about your solution in Delphi.
1) Why do you only loop to 89 and not 99?
2) What's with the A<>B thing?
3) I don't see where/if your solution addresses the "uniquely identifies"
constraint.
4) Why do you only check I & J values that are digit-wise mirror images of each
other? That doesn't look 'right', either.
Can you explain?
<---- Begin Forwarded Message ---->
Return-Path: <icon-group-sender@cs.arizona.edu>
From: jwormsley@debitek.com (Jeffrey A. Wormsley)
Subject: Re: New Scientist Puzzle
Date: Mon, 12 Mar 2001 15:03:36 -0000
To: icon-group@CS.Arizona.EDU
Can't help be throw a very verbose and fly right at it Delphi solution
in... Certaily isn't 5 lines like the K solution, but then I can't read
the K solution ;^).
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function Match(I,J : Integer): Boolean;
Procedure FindMatches;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TForm1.Match(I,J : Integer): Boolean;
Var S : String;
K, L : Byte;
Begin
Result := False; // Assume no match
S := IntToStr(Sqr(I)) + IntToStr(Sqr(J)); // Build string
If (S[3] <> S[6]) or (S[5] <> S[8]) then // Check the E's and N's
Exit; // Exit if not matched
S := S[1] + S[2] + S[3] + S[4] + S[5] + S[7]; // Remove dup E's and N's
For K := 1 to Length(S) - 1 Do // Scan for dups
For L := K + 1 to Length(S) Do
If S[K] = S[L] then // If dup found
Exit; // Exit
Result := True; // Good match if this far
End;
Procedure TForm1.FindMatches;
Var I, J, A, B : Byte;
Begin
For I := 34 to 89 do
Begin
A := I div 10; B := I mod 10; // Get digits
If A <> B then // Can't work if equal
Begin
J := A + (B * 10); // Transpose digits
If Match(I,J) then // Check for match
Memo1.Lines.Add( 'VIER = ' + IntToStr(Sqr(I)) +
' NEUN = ' + IntToStr(Sqr(J)) +
' (' + IntToStr(I) + ',' + IntToStr(J) + ')');
End;
End;
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindMatches;
end;
end.
Jeff.
<---- End Forwarded Message ---->
Gordon Peterson http://personal.terabites.com/
Support the Anti-SPAM Amendment! Join at http://www.cauce.org/
12/19/98: Partisan Republicans scornfully ignore the voters they "represent".
12/09/00: the date the Republican Party took down democracy in America.